package top.kaoshanji.ch12;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.ch12.forkjoin.Counter;

import java.util.concurrent.ForkJoinPool;

/**
 * 代码清单 ch12-08：fork-join框架示例(12.6.4节)
 * author kaoshanji
 * ^_^
 * create time 2024/11/30 11:36
 */
public class ForkJoinTest {

    private static final Logger logger = LogManager.getLogger(ForkJoinTest.class);

    public static void main(String[] args) {
        logger.info("...代码清单 ch12-08：fork-join框架示例(12.6.4节)...");

        final int SIZE = 10000000;
        var numbers = new double[SIZE];
        for (int i = 0; i < SIZE; i++) {
            numbers[i] = Math.random();
        }

        var counter = new Counter(numbers, 0, numbers.length, x -> x > 0.5);
        var pool = new ForkJoinPool();
        pool.invoke(counter);

        System.out.println(counter.join());

    }

}
